/*
 * @Author: Simon 1958058172@qq.com
 * @Date: 2025-08-11 16:07:03
 * @LastEditors: Simon 1958058172@qq.com
 * @LastEditTime: 2025-08-11 16:17:01
 * @FilePath: \java.1212\day06\work03\Test.java
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
package day06.work03;

import java.util.ArrayList;
import java.util.Collection;

public class Test {
    public static void main(String[] args) {
        Collection<Integer> list1=new ArrayList<>();
        Collection<Integer> list2=new ArrayList<>();
        list1.add(1);
        list1.add(2);
        list1.add(3);
        list1.add(4);
        list1.add(5);
        list2.add(4);
        list2.add(5);
        list2.add(6);

        //(1)交集
        Collection<Integer> jiao_coll=new ArrayList<>();
        for(Integer num:list1){
            if(list2.contains(num)){jiao_coll.add(num);}
        }
        for(Object object:jiao_coll.toArray()){
            System.out.println(object);
        }
//------------------------------------------------------------
System.out.println("-------------");
        //(2)差集
        Collection<Integer> cha_coll=new ArrayList<>();
        for(Integer num:list1){
            if(jiao_coll.contains(num)){}else{cha_coll.add(num);}
        }
        for(Integer num:list2){
            if(jiao_coll.contains(num)){}else{cha_coll.add(num);}
        }
        for(Object object:cha_coll.toArray()){
            System.out.println(object);
        }
    }
}
